<?php
require_once(dirname(__FILE__). '/app.php');

if ( $_POST ) {
    //if($_SESSION['captcha'] != strtoupper($_POST['captcha'])){
    //    Session::Set('error', '验证码错误！');
	//	redirect(WEB_ROOT . '/login.php');
    //}
	$login_user = ZUser::GetLogin($_POST['email'], $_POST['password']);
	if ( !$login_user ) {
		Session::Set('error', '用户名无效或密码错误！');
		redirect(WEB_ROOT . '/login.php');
	} else {
        Session::Set('user_id', $login_user['id']);
        
        if($_POST['remember']){ //记住登录状态
            ZLogin::Remember($login_user);
        }
		if($_POST['cache_username']){ //记住用户名
            setcookie("cache_username", $_POST['email'], time() + 86400*30);
        }
		
        
        ZUser::SynLogin($login_user['username'], $_POST['password']);
        ZCredit::Login($login_user['id']);
        redirect(get_loginpage(WEB_ROOT . '/index.php'));
	}
}


include template('login');